Use QString::compare(QStringView, Qt::CaseSensitivity) (#965)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 29 Dec 2022 19:02:28 +0000 (12:02 -0700)
committerGitHub <noreply@github.com>
Thu, 29 Dec 2022 19:02:28 +0000 (12:02 -0700)
* use QString::compare(QString, Qt::CaseSensitivity)

instead of case_ignore_strcmp with a QString and a character
literal.

* use QString::compare(QStringView, Qt::CaseSensitivity)

instead of QString::compare(QLatin1String, Qt::CaseSensitivity).

* compare QStrings to character literals instead of string literals that only contain one character.

garmin_device_xml.cc
garmin_txt.cc
gbfile.cc
gpx.cc
lowranceusr.cc
ozi.cc
shape.cc
unicsv.cc
xcsv.cc

index f880d0c969bd0c3a460f3576fc3004687e4abc0b..2b43a9e94e418d331fe8428c15da00b70de4f14b 100644 (file)
@@ -42,7 +42,7 @@ jmp_buf gdx_jmp_buf;
 
 static void type_s(xg_string args, const QXmlStreamAttributes*)
 {
-  type = args.compare(QLatin1String("GPSData"));
+  type = args.compare(u"GPSData");
 }
 
 void device_s(xg_string args, const QXmlStreamAttributes*)
index 46d4cd3f1c23812219d8643265cb44aaa4e7f123..dd24e4197851f9e8b42c429889ccae2470be2be4 100644 (file)
@@ -1391,23 +1391,23 @@ garmin_txt_read()
     auto linetype = lineparts.at(0);
     lineparts.removeFirst();
 
-    if (case_ignore_strcmp(linetype, "Header") == 0) {
+    if (linetype.compare(u"Header", Qt::CaseInsensitive) == 0) {
       parse_header(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Grid") == 0) {
+    } else if (linetype.compare(u"Grid", Qt::CaseInsensitive) == 0) {
       parse_grid(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Datum") == 0) {
+    } else if (linetype.compare(u"Datum", Qt::CaseInsensitive) == 0) {
       parse_datum(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Waypoint") == 0) {
+    } else if (linetype.compare(u"Waypoint", Qt::CaseInsensitive) == 0) {
       parse_waypoint(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Route Waypoint") == 0) {
+    } else if (linetype.compare(u"Route Waypoint", Qt::CaseInsensitive) == 0) {
       parse_route_waypoint(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Trackpoint") == 0) {
+    } else if (linetype.compare(u"Trackpoint", Qt::CaseInsensitive) == 0) {
       parse_track_waypoint(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Route") == 0) {
+    } else if (linetype.compare(u"Route", Qt::CaseInsensitive) == 0) {
       parse_route_header(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Track") == 0) {
+    } else if (linetype.compare(u"Track", Qt::CaseInsensitive) == 0) {
       parse_track_header(lineparts);
-    } else if (case_ignore_strcmp(linetype, "Map") == 0) /* do nothing */ ;
+    } else if (linetype.compare(u"Map", Qt::CaseInsensitive) == 0) /* do nothing */ ;
     else {
       fatal(MYNAME ": Unknown identifier (%s) at line %d!\n", qPrintable(linetype), current_line);
     }
index d3d6b9ec401e1675d137327639e877eb5816d6f4..cc810fa1cc94419cafebd87f74e5277e37347960 100644 (file)
--- a/gbfile.cc
+++ b/gbfile.cc
@@ -542,7 +542,7 @@ gbfopen(const QString& filename, const char* mode, const char* module)
     file->filewrite = memapi_write;
   } else {
     file->name = xstrdup(filename);
-    file->is_pipe = (filename == "-");
+    file->is_pipe = (filename == '-');
 
     /* Do we have a '.gz' extension in the filename ? */
     int len = strlen(file->name);
diff --git a/gpx.cc b/gpx.cc
index f671f42b8e0e4794e42d89094f97497a9a555277..e034de2549ef4fbc4cff523cb391fd898c590c3b 100644 (file)
--- a/gpx.cc
+++ b/gpx.cc
@@ -656,7 +656,7 @@ GpxFormat::gpx_end(QStringView /*unused*/)
    * last date we saw in this log.
    */
   case tt_cache_log_type:
-    if ((cdatastr.compare(QLatin1String("Found it")) == 0) &&
+    if ((cdatastr.compare(u"Found it") == 0) &&
         (0 == wpt_tmp->gc_data->last_found.toTime_t())) {
       wpt_tmp->AllocGCData()->last_found = gc_log_date;
     }
@@ -1154,7 +1154,7 @@ GpxFormat::fprint_xml_chain(XmlTag* tag, const Waypoint* wpt) const
         fprint_xml_chain(tag->child, wpt);
       }
       if (wpt && wpt->gc_data->exported.isValid() &&
-          tag->tagname.compare(QLatin1String("groundspeak:cache")) == 0) {
+          tag->tagname.compare(u"groundspeak:cache") == 0) {
         writer->writeTextElement(QStringLiteral("time"),
                                  wpt->gc_data->exported.toPrettyString());
       }
index 975eae8c268e673662c575273032fa6bd402bdee..e7bb1d39b048a03d0d8d200c0913d0e93ed265ab 100644 (file)
@@ -1346,7 +1346,7 @@ LowranceusrFormat::lowranceusr_waypt_disp(const Waypoint* wpt) const
 
   gbfputint32(waypt_time, file_out);
 
-  if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(QLatin1String("Geocache Found")) == 0) {
+  if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) {
     SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt));
   } else {
     SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr);
@@ -1407,7 +1407,7 @@ LowranceusrFormat::lowranceusr4_waypt_disp(const Waypoint* wpt)
   gbfputint32(2, file_out);
 
   int SymbolId, ColorId;
-  if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(QLatin1String("Geocache Found")) == 0) {
+  if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) {
     if (writing_version == 4) {
       SymbolId = lowranceusr4_find_icon_number_from_desc(wpt->icon_descr);
     } else {
diff --git a/ozi.cc b/ozi.cc
index 658a8a26be12864f5f51eecda066ee421b2846df..3bb429898168ee5b89a8d727ce2dd5d2a616eaff 100644 (file)
--- a/ozi.cc
+++ b/ozi.cc
@@ -233,7 +233,7 @@ ozi_openfile(const QString& fname)
    * mytrack.plt, mytrack-1.plt...unless we're writing to stdout.
    */
 
-  if (fname == "-") {
+  if (fname ==  '-') {
     if (stream == nullptr) {
       ozi_open_io(fname, QFile::WriteOnly);
     }
index 874ddb0aab36ab3e4b76a4e3074d9a6ba6e86be2..94321902b87a58e55f6d09e6d5bd76c1a81159cf 100644 (file)
--- a/shape.cc
+++ b/shape.cc
@@ -193,7 +193,7 @@ ShapeFormat::rd_init(const QString& fname)
   const char* codepage = DBFGetCodePage(ihandledb);
   if (codepage) {
     QString qcodepage(codepage);
-    if (qcodepage.compare(QLatin1String("UTF-8"), Qt::CaseInsensitive)) {
+    if (qcodepage.compare(u"UTF-8", Qt::CaseInsensitive)) {
       warning(MYNAME ": dbf file %s is in code page %s, but we always process dbf files as UTF-8.\n",qPrintable(ifname),codepage);
     }
   } else {
index 0f710b66606fb8135d7e07aba90ffc476249d533..ad6590c1f4f230b13cde82617556e080f39bc089 100644 (file)
--- a/unicsv.cc
+++ b/unicsv.cc
@@ -324,14 +324,14 @@ UnicsvFormat::unicsv_parse_time(const QString& str, int* msec, time_t* date)
 status_type
 UnicsvFormat::unicsv_parse_status(const QString& str)
 {
-  if (str.compare(QLatin1String("true"), Qt::CaseInsensitive) == 0 ||
-      str.compare(QLatin1String("yes"), Qt::CaseInsensitive) == 0 ||
-      str == "1") {
+  if (str.compare(u"true", Qt::CaseInsensitive) == 0 ||
+      str.compare(u"yes", Qt::CaseInsensitive) == 0 ||
+      str == '1') {
     return status_true;
   }
-  if (str.compare(QLatin1String("false"), Qt::CaseInsensitive) == 0 ||
-      str.compare(QLatin1String("no"), Qt::CaseInsensitive) == 0 ||
-      str == "0") {
+  if (str.compare(u"false", Qt::CaseInsensitive) == 0 ||
+      str.compare(u"no", Qt::CaseInsensitive) == 0 ||
+      str == '0') {
     return status_false;
   }
   return status_unknown;
@@ -668,15 +668,15 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf)
       if (unicsv_detect) {
         unicsv_data_type = trkdata;
       }
-      if (case_ignore_strcmp(value, "none") == 0) {
+      if (value.compare(u"none", Qt::CaseInsensitive) == 0) {
         wpt->fix = fix_none;
-      } else if (case_ignore_strcmp(value, "2d") == 0) {
+      } else if (value.compare(u"2d", Qt::CaseInsensitive) == 0) {
         wpt->fix = fix_2d;
-      } else if (case_ignore_strcmp(value, "3d") == 0) {
+      } else if (value.compare(u"3d", Qt::CaseInsensitive) == 0) {
         wpt->fix = fix_3d;
-      } else if (case_ignore_strcmp(value, "dgps") == 0) {
+      } else if (value.compare(u"dgps", Qt::CaseInsensitive) == 0) {
         wpt->fix = fix_dgps;
-      } else if (case_ignore_strcmp(value, "pps") == 0) {
+      } else if (value.compare(u"pps", Qt::CaseInsensitive) == 0) {
         wpt->fix = fix_pps;
       } else {
         wpt->fix = fix_unknown;
diff --git a/xcsv.cc b/xcsv.cc
index f062444a4251ba03f2e93e8c23d2ba9bf9aa79dd..9425e56d824dc67e7bf2f8f466acaab267c9a13d 100644 (file)
--- a/xcsv.cc
+++ b/xcsv.cc
@@ -676,9 +676,9 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle:
     break;
   case XcsvStyle::XT_GEOCACHE_ISAVAILABLE:
     gc_data = wpt->AllocGCData();
-    if (case_ignore_strcmp(value.trimmed(), "False") == 0) {
+    if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) {
       gc_data->is_available = status_false;
-    } else if (case_ignore_strcmp(value.trimmed(), "True") == 0) {
+    } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) {
       gc_data->is_available = status_true;
     } else {
       gc_data->is_available = status_unknown;
@@ -686,9 +686,9 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle:
     break;
   case XcsvStyle::XT_GEOCACHE_ISARCHIVED:
     gc_data = wpt->AllocGCData();
-    if (case_ignore_strcmp(value.trimmed(), "False") == 0) {
+    if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) {
       gc_data->is_archived = status_false;
-    } else if (case_ignore_strcmp(value.trimmed(), "True") == 0) {
+    } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) {
       gc_data->is_archived = status_true;
     } else {
       gc_data->is_archived = status_unknown;
@@ -711,11 +711,11 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle:
   case XcsvStyle::XT_GPS_FIX:
     wpt->fix = (fix_type)(xstrtoi(s, nullptr, 10)-(fix_type)1);
     if (wpt->fix < fix_2d) {
-      if (!case_ignore_strcmp(value, "none")) {
+      if (!value.compare(u"none", Qt::CaseInsensitive)) {
         wpt->fix = fix_none;
-      } else if (!case_ignore_strcmp(value, "dgps")) {
+      } else if (!value.compare(u"dgps", Qt::CaseInsensitive)) {
         wpt->fix = fix_dgps;
-      } else if (!case_ignore_strcmp(value, "pps")) {
+      } else if (!value.compare(u"pps", Qt::CaseInsensitive)) {
         wpt->fix = fix_pps;
       } else {
         wpt->fix = fix_unknown;